class ApplicationMailer < ActionMailer::Base

  def contact_us(data)
    recipients   Setting.application_mail_contact_us
    cc           data[:email]
    from         Setting.application_mail_from
    sent_on      Time.now
    subject      data[:subject]
    content_type "plain/text"

    #parametros para la vista
    body["data"]    = data
  end

  def general_news(contact, news_letter, materials)
    recipients   contact.email #pmrp@adinet.com.uy  rodriguezp.pablo@gmail.com
    from         Setting.application_mail_from
    sent_on      Time.now

    I18n.locale = contact.language

    if contact.is_spanish?
      subject_str = news_letter.subject_mail_spanish
    else
      subject_str = news_letter.subject_mail_english
    end

    subject      subject_str

    #parametros para la vista
    body["contact"]    = contact
    body["materials"]  = materials
    body["news_letter"]  = news_letter
    
    if contact.mail_format == "html"      
      content_type "text/html"
      part :content_type => "text/html", :body => render_message("general_news_html.rhtml", :contact => contact, :news_letter => news_letter, :materials => materials)
=begin
      content_type "multipart/mixed"
      part :content_type => "text/html", :body => render_message("general_news_html.rhtml", :contact => contact, :news_letter => news_letter, :materials => materials)
      materials.each do |material|
        content_type = case File.extname(material.image)
          when ".jpg" , ".jpeg" ; "image/jpeg"
          when ".png" ; "image/png"
          when ".gif" ; "image/gif"
          else; "application/octet-stream"
        end
        attachment :content_type => content_type, :body => File.read(File.join(Setting.image_path_absolute , material.image)), :filename => File.basename(material.image)
      end
=end
    else
      content_type "text/html"
      part :content_type => "text/html", :body => render_message("general_news_text.rhtml", :contact => contact, :news_letter => news_letter, :materials => materials)
    end
  end
  
end
